package com.example.mvvmdemo.db;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.example.mvvmdemo.model.User;

/**
 * @author: tuyrt7 on 2020/8/31.
 * Describe:
 */
@Database(entities = {User.class}, version = 1)
public abstract class UserDatabase extends RoomDatabase {

    private static final String DATABASE_NAME = "user_db";

    private static  UserDatabase database;

    public static synchronized UserDatabase get(Context context) {
        if (database == null) {
            database = Room.databaseBuilder(context.getApplicationContext(), UserDatabase.class, DATABASE_NAME).build();
        }
        return database;
    }

    public abstract UserDao userDao();

}
